
#include "Tile.h"

Tile::Tile(){

	tileNum = 0;
	
	tilesetSurface = NULL;
	tileset = NULL;

	currentTileRect.x = currentTileRect.y = 0;
	currentTileRect.h = currentTileRect.w = 0;
}

bool Tile::init(Tileset* _tileset, SDL_Surface* tilesetImage){

	tilesetSurface = tilesetImage;
	tileset = _tileset;

	currentTileRect.h = currentTileRect.w = tileset->getTileSize();

	return true;
}

void Tile::loop(){
	
}

void Tile::render(SDL_Surface* destSurface, int x, int y){
	Surface::OnDraw(destSurface, tilesetSurface, x, y, currentTileRect.x, currentTileRect.y, 
					currentTileRect.w, currentTileRect.h);
}

void Tile::cleanup(){

	tilesetSurface = NULL;
	tileset = NULL;
}

void Tile::setType(int t){
	
	if(t == tileNum)
		return;

	tileNum = t;
	currentTileRect.x = ( t % tileset->getTilesetWidth() ) * tileset->getTileSize();
	currentTileRect.y = ( t / tileset->getTilesetWidth() ) * tileset->getTileSize();
}



